import requests
class MyRequests:
    def __init__(self):
        self.headers = {}

    def send_requests(self, url, method, data=None, token=None):
        # 处理请求头
        self.__del__headers(token)
        if method.upper() == "GET":
            resp = requests.request(method, url, params=data, headers=self.headers)
        else:
            resp = requests.request(method, url, json=data, headers=self.headers)
        return resp

    def __del__headers(self, token=None):
        if token:
            self.headers["token"] = "{}".format(token)

if __name__ == '__main__':
    mr = MyRequests()
    url = "https://yunyan-test.frp.xxbu.cn/api/sasc-aggregation-property-web/login"
    req_data = {
        "loginType": "0",
        "password": "12345678",
        "username": "125@qq.com",
        "userType": "0"}
    method = "post"
    resp = mr.send_requests(url, method, req_data)
    resp_dict = resp.json()
    token = resp_dict["data"]["token"]
    print(resp.json())

    url2 = "https://yunyan-test.frp.xxbu.cn/api/sasc-aggregation-property-web/enterprise/update"
    req_data2 = {
        "address": "4id都ianb1打16628837181",
        "channel": "1",
        "contact": "333",
        "email": "125@qq.com",
        "enabled": "true",
        "expireTime": "4102329599",
        "gmtCreate": "1643075084",
        "id": "164307508400001",
        "maxCommunityAmount": "33",
        "mobile": "13759763920",
        "name": "2022125测试"}
    method2 = "post"
    resp2 = mr.send_requests(url2, method2, req_data2, token=token)
    print(resp2.json())

    url3 = "https://yunyan-test.frp.xxbu.cn/api/sasc-aggregation-property-web/house/query?pageSize=10&pageNum=1&query=community_id:eq:164506857300001;type:eq:;identifier:like:;state:eq:;or;house_name:like:%%;household_mobile:like:%%;household_name:like:%%"
    method3 = "GET"
    resp3 = mr.send_requests(url3, method3, token=token)
    print(resp3.json())